package vip.xiaonuo.core.util;

import com.alibaba.fastjson2.JSONObject;
import ink.rayin.htmladapter.base.PdfGenerator;
import ink.rayin.htmladapter.base.Signature;
import ink.rayin.htmladapter.openhtmltopdf.service.PdfBoxGenerator;
import ink.rayin.htmladapter.openhtmltopdf.service.PdfBoxSignature;
import ink.rayin.tools.utils.ResourceUtil;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;

public class PDTCommUtils {
    static PdfGenerator pdfGenerator;
    Signature pdfSign = new PdfBoxSignature();
    static  {
        try {
            pdfGenerator = new PdfBoxGenerator();
            pdfGenerator.init();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void genderPdf(String classPathHtml, JSONObject jsonObject,String outputStream) throws IOException {
         pdfGenerator.generatePdfFileByHtmlAndData(ResourceUtil.getResourceAbsolutePathByClassPath(classPathHtml), jsonObject,outputStream);
    }

    public static ByteArrayOutputStream genderPdf(String classPathHtml, JSONObject jsonObject) throws IOException {
        String s = pdfGenerator.htmlFileDataFilling(classPathHtml, jsonObject);
        return   pdfGenerator.generatePdfSteamByHtmlStrAndData(s,jsonObject);
    }

//    public static ByteArrayOutputStream genderPdf(String classPathHtml, JSONObject jsonObject,ByteArrayOutputStream outputStream){
//        return pdfGenerator.generatePdfStreamByTplConfigStr(classPathHtml,jsonObject,outputStream);
//    }

}
